package net.towee.model.account.impl;

import java.util.HashMap;

import net.towee.model.account.Gadget;
import net.towee.model.impl.SettingsImpl;

import com.google.code.morphia.annotations.Embedded;
import com.google.code.morphia.annotations.PostLoad;

/**
 * Implementation of gadget on a board
 * @author c58
 */
@Embedded
public class GadgetImpl extends SettingsImpl implements Gadget {
	// Gadget identity name
	private String name;
	
	// Minimize state
	private boolean minimized;
	
	// Position of gadget
	private int row = 0;
	private int cel = 0;
	
	public GadgetImpl() {}
	public GadgetImpl(String name) {
		this.name = name;
		this.settings = new HashMap<String, String>();
		this.minimized = false;
	}
	
	@PostLoad
	private void createEmptyFields() {
		if(settings == null)
			this.settings = new HashMap<String, String>();
	}

	@Override
	public String getGadgetName() {
		return name;
	}

	@Override
	public boolean isMinimized() {
		return minimized;
	}

	@Override
	public void setMinimized(boolean state) {
		this.minimized = state;
	}
	@Override
	public int getRow() {
		return row;
	}
	@Override
	public int getCel() {
		return cel;
	}
	@Override
	public void setRow(int row) {
		this.row = row;
	}
	@Override
	public void setCel(int col) {
		this.cel = col;
	}

	@Override
	public boolean equals(Object o){
		if(o == this)
			return true;
		else if(o instanceof Gadget && ((Gadget)o).getGadgetName().equals(getGadgetName()))
			return true;
		
		return false;
	}
}
